\begin{verbatim}
def coincidence_discriminant(S)
    """
    INPUT: A sequence of 2-character strings, produced 
    as decimation of transposition ciphertext, or of 
    adjacent characters in some sample plaintext.
    OUTPUT: A measure of the difference of probability 
    of association of two characters, relative to their 
    independent probabilities.
    """
    AZ = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    AA = [ AZ[i] + AZ[j] for i in range(26) for j in range(26) ]
    X1 = frequency_distribution(''.join([ s[0] for s in S ]))
    X2 = frequency_distribution(''.join([ s[1] for s in S ]))
    F2 = {}
    N = len(S)
    RR = RealField()
    ee = RR(1/N)
    for AB in S:
        if F2.has_key(AB):
            F2[AB] += eps
        else:
            F2[AB] = eps
    return sum([ (F2[AZ[i]+AZ[j]]-X1[AZ[]*X2[j])^2 
        for i in range(26) for j in range(26) ])
\end{verbatim}
